package it.csi.finregio.finreges.client.services;

import it.crp.crparch.web.struts.service.CRPStrutsService;
import it.crp.crparch.web.struts.service.WebServiceException;
import it.crp.logger.PrdLoggerFactory;
import it.csi.finregio.finreges.client.ServiceLocator;
import it.csi.finregio.finreges.dto.Scheda;
import it.csi.finregio.finreges.integration.SchedaService;
import it.csi.finregio.finreges.presentation.form.SchedaForm;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;

public class EliminaSchedaService implements CRPStrutsService {

	private Logger log = PrdLoggerFactory.getInstance().getLogger("finreges");
	public Object execute(ActionForm form) throws WebServiceException {
		log.info("[EliminaSchedaService::execute] BEGIN");
		Boolean ok = new Boolean(false);
		try {
			SchedaForm sf = (SchedaForm) form;
			SchedaService service = new ServiceLocator().getSchedaService();
			Scheda scheda = new Scheda();
			scheda.setIdScheda(sf.getIdScheda());
			scheda.setAnno(sf.getAnno());
			scheda.setNumeroQuaderno(sf.getNumeroQuaderno());
			log.debug("[EliminaSchedaService::execute] Delete scheda with id "+scheda.getIdScheda());
			boolean result = service.deleteScheda(scheda);
			ok = new Boolean(result);
			log.debug("[EliminaSchedaService::execute] Scheda deleted!! "+result);
			return ok;
		} catch (Exception e) {
			log.error("[EliminaSchedaService::execute]  "
					+ e.getMessage(), e);
			throw new WebServiceException(e.getMessage());
		}finally{
			log.info("[EliminaSchedaService::enclosing_method] END");
		}
	}

}
